package cn.com.freelibra.forum.service.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import cn.com.freelibra.forum.dao.SectionMapper;
import cn.com.freelibra.forum.po.Section;
import cn.com.freelibra.forum.service.SectionService;

@Service("sectionService")  
public class SectionServiceImpl implements SectionService{
    @Resource  
    private SectionMapper dao;
    
    @Override
	public int add(Section entity) {
		return dao.insert(entity);
	}
    
	@Override
	public Section load(Long id) {
		return dao.selectByPrimaryKey(id);
	}

	@Override
	public Page<Map<String, Object>> selectSectionJoinUserList(String keyword,Integer pageNumber,Integer pageSize) {
		pageNumber = pageNumber == null?1:pageNumber;
		pageSize = pageSize == null?5:pageSize;
		PageHelper.startPage(pageNumber,pageSize);
		keyword = (keyword==null||"".equals(keyword.trim()))?null:("%"+keyword+"%");
		Page<Map<String, Object>>  map = dao.selectSectionJoinUserList(keyword);
		return map;
	}
	
	@Override
	public Map<String, Object> selectSectionJoinUserByOne(Long sectionId){
		Map<String, Object> map = dao.selectSectionJoinUserByOne(sectionId);
		return map;
	}
	
}
